package classes;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;

public class StorageQuran {

	public static void storeEnglish() {
		try {
			// Open the file that is the first
			// command line parameter
			FileInputStream fstream = new FileInputStream(
					"English-Ahmed-Ali-100.txt");
			// Get the object of DataInputStream
			DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String strLine;
			Connect c = new Connect();
			Connection conn = null;
			conn = c.getConnection();
			// Read File Line By Line
			while ((strLine = br.readLine()) != null) {
				System.out.println("in insertion \n");
				String latest = "" + strLine + "";
				System.out.println(strLine);
				c.execute(conn, latest, true);
			}
			// Close the input stream
			in.close();
		} catch (Exception e) {// Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}

	public static void storeUrdu() {
		try {
			Connect c = new Connect();
			Connection conn = null;
			conn = c.getConnection();
			File fileDir = new File("Arabic.txt");
			BufferedReader in = new BufferedReader(new InputStreamReader(
					new FileInputStream(fileDir), "UTF8"));
			String str;
			str = in.readLine();
			str = str.substring(1);
			c.execute(conn, str, true);
			while ((str = in.readLine()) != null) {
				System.out.println(str);
				c.execute(conn, str, true);
			}
			in.close();
		} catch (UnsupportedEncodingException e) {
			System.out.println(e.getMessage());
		} catch (IOException e) {
			System.out.println(e.getMessage());
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

	public static void main(String[] args) throws SQLException {
		Connect c = new Connect();
		Connection conn = null;
		conn = c.getConnection();
		c.execute(conn, "use quranhadith;", true);
		System.out.println("database selected");
		storeUrdu();
		conn.close();
	}
}